﻿using System;
using System.Windows.Forms;

namespace AdvancedScriptEditor
{
    public partial class FunctionEditorAddFunction : Form
    {
        FunctionList functionList;
        string appPath;

        public FunctionEditorAddFunction(FunctionList functionlist)
        {
            InitializeComponent();
            functionList = functionlist;
            appPath = Properties.Settings.Default.AppPath;
        }

        private void btn_AddFunction_Click(object sender, EventArgs e)
        {
            string[] functions = new string[functionList.Functions.Length + 1];
            string[] descriptions = new string[functionList.Descriptions.Length + 1];

            for (int i = 0; i < functionList.Functions.Length; i++)
                functions[i] = functionList.Functions[i];
            for (int i = 0; i < functionList.Descriptions.Length; i++)
                descriptions[i] = functionList.Descriptions[i];

            functions[functions.Length - 1] = txtbx_FunctionName.Text;
            descriptions[descriptions.Length - 1] = rtb_FunctionDescription.Text;
            functionList.Functions = functions;
            functionList.Descriptions = descriptions;

            functionList.Save(appPath + "\\tempfunctions.txt", appPath + "\\tempdescriptions.txt");
            MessageBox.Show("Changes saved.");
            this.Close();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
